package com.joker.utils;

import lombok.Data;

/**
 * <p>
 *  封装返回结果集
 * </p>
 *
 * @author joker
 * @since 2021-06-03
 */
@Data
public class ResultUtil<T> {
    /**
     * 返回状态码
     */

    private Integer code;
    /**
     * 消息提示
     */

    private String msg;

    /**
     * 返回的数据
     */

    private T data;

    /**
     * 操作成功
     * @param data 返回的数据
     *
     *
     * @author joker
     * @since 2021-06-03
     */
    public static <T> ResultUtil<T> success(T data){
        ResultUtil<T> result = new ResultUtil<T>();
        result.setCode(200);
        result.setMsg("操作成功");
        result.setData(data);
        return result;
    }
    /**
     * 操作成功
     * @param data 返回的数据
     *@param msg 操作成功描述
     *
     * @author joker
     * @since 2021-06-03
     */
    public static <T> ResultUtil<T> success(T data,String msg){
        ResultUtil<T> result = new ResultUtil<T>();
        result.setCode(200);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    /**
     * 操作失败
     * @param msg 错误描述
     *
     *
     * @author joker
     * @since 2021-06-03
     */
    public static <T> ResultUtil<T> error(String msg){
        ResultUtil<T> result = new ResultUtil<T>();
        result.setCode(201);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }
}
